package com.momo.web.controller.sysSetting;

import com.momo.common.common.JSONResult;
import com.momo.common.req.sysSetting.RouteReq;
import com.momo.common.req.sysSetting.route.RouteDefinition;
import com.momo.service.sysSetting.SysRoutesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by MOMO on 2019/2/27.
 */
@RestController
@RequestMapping(value = "/platform/route", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@Slf4j
public class SysRoutesController {
    @Autowired
    private SysRoutesService sysRoutesService;

    /**
     *  rabbitmq 更新路由到网关层本地map
     *
     * @param routeReq
     * @return
     */
    @PostMapping("/addRouteToGatewayLocalMapByMQ/v1")
    public JSONResult addRouteToGatewayLocalMapByMQ(@RequestBody RouteReq routeReq) {
        sysRoutesService.addRouteToGatewayLocalMapByMQ(routeReq);
        return JSONResult.ok("更新路由到网关层本地map成功");
    }


    /**
     * 数据库动态路由分页查询
     *
     * @param routeReq
     * @return
     */
    @PostMapping("/getRouteAll/v1")
    public JSONResult getRouteAll(@RequestBody RouteReq routeReq) {
        return JSONResult.ok(sysRoutesService.getRouteAll(routeReq));
    }

    /**
     * 数据库 新增动态路由
     *
     * @param routeDefinition
     * @return
     */
    @PostMapping("/addRoute/v1")
    public JSONResult addRoute(@RequestBody RouteDefinition routeDefinition) {
        sysRoutesService.addRoute(routeDefinition);
        return JSONResult.ok("新增路由成功");
    }

    /**
     * 数据库 编辑动态路由
     *
     * @param routeDefinition
     * @return
     */
    @PostMapping("/modifyRoute/v1")
    public JSONResult modifyRoute(@RequestBody RouteDefinition routeDefinition) {
        sysRoutesService.modifyRoute(routeDefinition);
        return JSONResult.ok("编辑路由成功");
    }
}
